<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>分类: 技术教程 | 小小程序员</title><meta name="author" content="十一星野"><meta name="copyright" content="十一星野"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="天天在用 SpringBoot，但有些 SpringBoot 的实用知识点却不是很清楚！最近又对 SpringBoot 中的实用知识点做了个总结，相信对从 Spring 过渡到 SpringBoot 的朋友会很有帮助！  #前言首先我们来了解下为什么要有SpringBoot？ Spring作为J2EE的轻量级代替品，让我们无需开发重量级的Enterprise JavaBean（EJB），通过依赖">
<meta property="og:type" content="article">
<meta property="og:title" content="肝了一周总结的SpringBoot实战教程，太实用了！">
<meta property="og:url" content="https://ko25891wan.gitlab.io/2024/01/1e0f014a2244.html">
<meta property="og:site_name" content="小小程序员">
<meta property="og:description" content="天天在用 SpringBoot，但有些 SpringBoot 的实用知识点却不是很清楚！最近又对 SpringBoot 中的实用知识点做了个总结，相信对从 Spring 过渡到 SpringBoot 的朋友会很有帮助！  #前言首先我们来了解下为什么要有SpringBoot？ Spring作为J2EE的轻量级代替品，让我们无需开发重量级的Enterprise JavaBean（EJB），通过依赖">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png">
<meta property="article:published_time" content="2024-01-21T09:28:28.000Z">
<meta property="article:modified_time" content="2024-02-02T13:40:55.041Z">
<meta property="article:author" content="十一星野">
<meta property="article:tag" content="宅男,热血">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://ko25891wan.gitlab.io/2024/01/1e0f014a2244.html"><link rel="preconnect" href="//fastly.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.5.1/css/all.min.css"><link rel="stylesheet" href="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: {"defaultEncoding":1,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.staticfile.org/egjs-infinitegrid/4.11.0/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '分类: 技术教程',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-02-02 21:40:55'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (false) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="小小程序员"><span class="site-name">小小程序员</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">肝了一周总结的SpringBoot实战教程，太实用了！</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2024-01-21T09:28:28.000Z" title="发表于 2024-01-21 17:28:28">2024-01-21</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-02-02T13:40:55.041Z" title="更新于 2024-02-02 21:40:55">2024-02-02</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/">技术教程</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/">mall</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/%E5%8F%82%E8%80%83%E7%AF%87/">参考篇</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">6.1k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>28分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="肝了一周总结的SpringBoot实战教程，太实用了！"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><blockquote>
<p>天天在用 SpringBoot，但有些 SpringBoot 的实用知识点却不是很清楚！最近又对 SpringBoot 中的实用知识点做了个总结，相信对从 Spring 过渡到 SpringBoot 的朋友会很有帮助！</p>
</blockquote>
<h2 id="前言"><a href="#前言" class="headerlink" title="#前言"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E5%89%8D%E8%A8%80">#</a>前言</h2><p>首先我们来了解下为什么要有SpringBoot？</p>
<p>Spring作为J2EE的轻量级代替品，让我们无需开发重量级的Enterprise JavaBean（EJB），通过依赖注入和面向切面编程，使用简单的Java对象（POJO）即可实现EJB的功能。</p>
<p>虽然Spring的组件代码是轻量级的，但它的配置却是重量级的。即使后来Spring引入了基于注解的组件扫描和基于Java的配置，让它看上去简洁不少，但Spring还是需要不少配置。除此之外，项目的依赖管理也很麻烦，我们无法确保各个版本的依赖都能兼容。</p>
<p>为了简化Spring中的配置和统一各种依赖的版本，SpringBoot诞生了！</p>
<h2 id="简介"><a href="#简介" class="headerlink" title="#简介"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E7%AE%80%E4%BB%8B">#</a>简介</h2><p>SpringBoot从本质上来说就是Spring，它通过了一些自己的特性帮助我们简化了Spring应用程序的开发。主要有以下三个核心特性：</p>
<ul>
<li>自动配置：对于很多Spring应用程序常见的应用功能，SpringBoot能自动提供相关配置，集成功能开发者仅需很少的配置。</li>
<li>起步依赖：告诉SpringBoot需要什么功能，它就能引入对应的库，无需考虑该功能依赖库的版本问题。</li>
<li>Actuator：可以深入了解SpringBoot应用程序内部情况，比如创建了哪些Bean、自动配置的决策、应用程序的状态信息等。</li>
</ul>
<h2 id="开始使用"><a href="#开始使用" class="headerlink" title="#开始使用"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E5%BC%80%E5%A7%8B%E4%BD%BF%E7%94%A8">#</a>开始使用</h2><h3 id="创建应用"><a href="#创建应用" class="headerlink" title="#创建应用"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E5%88%9B%E5%BB%BA%E5%BA%94%E7%94%A8">#</a>创建应用</h3><blockquote>
<p>创建SpringBoot应用的方式有很多种，这里使用最流行的开发工具IDEA来创建应用。</p>
</blockquote>
<ul>
<li>首先通过<code>File-&gt;New Project</code>来创建一个项目；</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/springboot_start_01-2f821229.png"></p>
<ul>
<li>然后选择通过<code>Spring Initializr</code>来创建一个SpringBoot应用；</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/springboot_start_02-b9461fb3.png"></p>
<ul>
<li>填写好Maven项目的<code>groupId</code>和<code>artifactId</code>及选择好Java版本；</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/springboot_start_03-5b32dcc3.png"></p>
<ul>
<li>选择好起步依赖，这里选择的是开启Web功能的起步依赖；</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/springboot_start_04-9c9caab2.png"></p>
<ul>
<li>选择好项目的存放位置即可顺利创建一个SpringBoot应用。</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/springboot_start_05-9bfafe5d.png"></p>
<h3 id="查看应用"><a href="#查看应用" class="headerlink" title="#查看应用"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E6%9F%A5%E7%9C%8B%E5%BA%94%E7%94%A8">#</a>查看应用</h3><h4 id="项目结构"><a href="#项目结构" class="headerlink" title="#项目结构"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84">#</a>项目结构</h4><p>一个新创建的SpringBoot应用基本结构如下。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">mall-tiny-boot</span><br><span class="line">├─pom.xml # Maven构建文件</span><br><span class="line">└─src</span><br><span class="line">   ├─main</span><br><span class="line">   │  ├─java</span><br><span class="line">   │  │  └─MallTinyApplication.java # 应用程序启动类</span><br><span class="line">   │  └─resources</span><br><span class="line">   │     └─application.yml # SpringBoot配置文件</span><br><span class="line">   └─test</span><br><span class="line">       └─java</span><br><span class="line">           └─MallTinyApplicationTests.java # 基本的集成测试类</span><br></pre></td></tr></table></figure>

<h4 id="应用启动类"><a href="#应用启动类" class="headerlink" title="#应用启动类"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E5%BA%94%E7%94%A8%E5%90%AF%E5%8A%A8%E7%B1%BB">#</a>应用启动类</h4><p><code>MallTinyApplication</code>在SpringBoot应用中有配置和引导的作用，通过<code>@SpringBootApplication</code>注解开启组件扫描和自动配置，通过<code>SpringApplication.run()</code>引导应用程序启动；</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">//开启组件扫描和应用装配</span><br><span class="line">@SpringBootApplication</span><br><span class="line">public class MallTinyApplication &#123;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        //负责引导应用程序启动</span><br><span class="line">        SpringApplication.run(MallTinyApplication.class, args);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><code>@SpringBootApplication</code>注解是三个注解的结合体，拥有以下三个注解的功能：</p>
<ul>
<li><code>@Configuration</code>：用于声明Spring中的Java配置；</li>
<li><code>@ComponentScan</code>：启用组件扫描，当我们声明组件时，会自动发现并注册为Spring应用上下文中的Bean；</li>
<li><code>@EnableAutoConfiguration</code>：开启SpringBoot自动配置功能，简化配置编写。</li>
</ul>
<h4 id="测试应用"><a href="#测试应用" class="headerlink" title="#测试应用"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E6%B5%8B%E8%AF%95%E5%BA%94%E7%94%A8">#</a>测试应用</h4><p>可以使用<code>@RunWith</code>和<code>@SpringBootTest</code>来创建Spring应用上下文，通过<code>@Test</code>注解来声明一个测试方法。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">@RunWith(SpringRunner.class)</span><br><span class="line">@SpringBootTest</span><br><span class="line">@Slf4j</span><br><span class="line">public class MallTinyApplicationTests &#123;</span><br><span class="line">    @Autowired</span><br><span class="line">    private PmsBrandService pmsBrandService;</span><br><span class="line"></span><br><span class="line">    @Test</span><br><span class="line">    public void contextLoads() &#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Test</span><br><span class="line">    public void testMethod() &#123;</span><br><span class="line">        List&lt;PmsBrand&gt; brandList = pmsBrandService.listAllBrand();</span><br><span class="line">        log.info(&quot;testMethod:&#123;&#125;&quot;, brandList);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="编写应用配置"><a href="#编写应用配置" class="headerlink" title="#编写应用配置"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E7%BC%96%E5%86%99%E5%BA%94%E7%94%A8%E9%85%8D%E7%BD%AE">#</a>编写应用配置</h4><p>当我们需要微调自动配置的参数时，可以在<code>application.yml</code>文件中进行配置，比如微调下端口号。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">server:</span><br><span class="line">  port: 8088</span><br></pre></td></tr></table></figure>

<h4 id="项目构建过程"><a href="#项目构建过程" class="headerlink" title="#项目构建过程"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E9%A1%B9%E7%9B%AE%E6%9E%84%E5%BB%BA%E8%BF%87%E7%A8%8B">#</a>项目构建过程</h4><p>SpringBoot项目可以使用Maven进行构建，首先我们需要继承<code>spring-boot-starter-parent</code>这个父依赖，父依赖可以控制所有SpringBoot官方起步依赖的版本，接下来当我们使用官方起步依赖时，就不用指定版本号了。我们还需要使用SpringBoot的插件，该插件主要用于将应用打包为可执行Jar。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span><br><span class="line">&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span><br><span class="line">         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;</span><br><span class="line">    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;</span><br><span class="line">    &lt;groupId&gt;com.macro.mall&lt;/groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;mall-tiny-boot&lt;/artifactId&gt;</span><br><span class="line">    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;</span><br><span class="line">    &lt;name&gt;mall-tiny-boot&lt;/name&gt;</span><br><span class="line">    &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;</span><br><span class="line"></span><br><span class="line">    &lt;properties&gt;</span><br><span class="line">        &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;</span><br><span class="line">        &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;</span><br><span class="line">        &lt;java.version&gt;1.8&lt;/java.version&gt;</span><br><span class="line">        &lt;skipTests&gt;true&lt;/skipTests&gt;</span><br><span class="line">    &lt;/properties&gt;</span><br><span class="line">    </span><br><span class="line">    &lt;!--继承SpringBoot父项目，控制所有依赖版本--&gt;</span><br><span class="line">    &lt;parent&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;</span><br><span class="line">        &lt;version&gt;2.3.0.RELEASE&lt;/version&gt;</span><br><span class="line">        &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;</span><br><span class="line">    &lt;/parent&gt;</span><br><span class="line">    &lt;dependencies&gt;</span><br><span class="line">        &lt;!--SpringBoot起步依赖--&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;</span><br><span class="line">            &lt;scope&gt;test&lt;/scope&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line">    &lt;/dependencies&gt;</span><br><span class="line"></span><br><span class="line">    &lt;build&gt;</span><br><span class="line">        &lt;plugins&gt;</span><br><span class="line">            &lt;plugin&gt;</span><br><span class="line">                &lt;!--SpringBoot插件，可以把应用打包为可执行Jar--&gt;</span><br><span class="line">                &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">                &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;</span><br><span class="line">            &lt;/plugin&gt;</span><br><span class="line">        &lt;/plugins&gt;</span><br><span class="line">    &lt;/build&gt;</span><br><span class="line"></span><br><span class="line">&lt;/project&gt;</span><br></pre></td></tr></table></figure>

<h3 id="使用起步依赖"><a href="#使用起步依赖" class="headerlink" title="#使用起步依赖"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E4%BD%BF%E7%94%A8%E8%B5%B7%E6%AD%A5%E4%BE%9D%E8%B5%96">#</a>使用起步依赖</h3><h4 id="使用起步依赖的好处"><a href="#使用起步依赖的好处" class="headerlink" title="#使用起步依赖的好处"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E4%BD%BF%E7%94%A8%E8%B5%B7%E6%AD%A5%E4%BE%9D%E8%B5%96%E7%9A%84%E5%A5%BD%E5%A4%84">#</a>使用起步依赖的好处</h4><p>在使用起步依赖之前，我们先来了解下使用起步依赖的好处，当我们使用SpringBoot需要整合Web相关功能时，只需在<code>pom.xml</code>中添加一个起步依赖即可。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;</span><br><span class="line">&lt;/dependency&gt;</span><br></pre></td></tr></table></figure>

<p>如果是Spring项目的话，我们需要添加很多依赖，还需要考虑各个依赖版本的兼容性问题，是个相当麻烦的事情。</p>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/springboot_start_06-0d0a0fc4.png"></p>
<h4 id="指定基于功能的依赖"><a href="#指定基于功能的依赖" class="headerlink" title="#指定基于功能的依赖"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E6%8C%87%E5%AE%9A%E5%9F%BA%E4%BA%8E%E5%8A%9F%E8%83%BD%E7%9A%84%E4%BE%9D%E8%B5%96">#</a>指定基于功能的依赖</h4><p>当我们需要开发一个Web应用，需要使用MySQL数据库进行存储，使用Swagger生成API文档，添加如下起步依赖即可。需要注意的是只有官方的起步依赖不需要指定版本号，其他的还是需要自行指定的。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependencies&gt;</span><br><span class="line">    &lt;!--SpringBoot Web功能起步依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;</span><br><span class="line">        &lt;scope&gt;test&lt;/scope&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--MyBatis分页插件--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;com.github.pagehelper&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;pagehelper-spring-boot-starter&lt;/artifactId&gt;</span><br><span class="line">        &lt;version&gt;1.2.10&lt;/version&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--集成druid连接池--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;com.alibaba&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;druid-spring-boot-starter&lt;/artifactId&gt;</span><br><span class="line">        &lt;version&gt;1.1.10&lt;/version&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--Mysql数据库驱动--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;mysql&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;</span><br><span class="line">        &lt;version&gt;8.0.15&lt;/version&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--springfox swagger官方Starter--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;io.springfox&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;springfox-boot-starter&lt;/artifactId&gt;</span><br><span class="line">        &lt;version&gt;3.0.0&lt;/version&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">&lt;/dependencies&gt;</span><br></pre></td></tr></table></figure>

<h4 id="覆盖起步依赖中的库"><a href="#覆盖起步依赖中的库" class="headerlink" title="#覆盖起步依赖中的库"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E8%A6%86%E7%9B%96%E8%B5%B7%E6%AD%A5%E4%BE%9D%E8%B5%96%E4%B8%AD%E7%9A%84%E5%BA%93">#</a>覆盖起步依赖中的库</h4><p>其实起步依赖和你平时使用的依赖没什么区别，你可以使用Maven的方式来排除不想要的依赖。比如你不想使用tomcat容器，想使用undertow容器，可以在Web功能依赖中排除掉tomcat。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependencies&gt;</span><br><span class="line">    &lt;!--SpringBoot Web功能起步依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;</span><br><span class="line">        &lt;exclusions&gt;</span><br><span class="line">            &lt;!--排除tomcat依赖--&gt;</span><br><span class="line">            &lt;exclusion&gt;</span><br><span class="line">                &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;</span><br><span class="line">                &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">            &lt;/exclusion&gt;</span><br><span class="line">        &lt;/exclusions&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--undertow容器--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-undertow&lt;/artifactId&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">&lt;/dependencies&gt;</span><br></pre></td></tr></table></figure>

<h3 id="使用自动配置"><a href="#使用自动配置" class="headerlink" title="#使用自动配置"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E4%BD%BF%E7%94%A8%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE">#</a>使用自动配置</h3><p>SpringBoot的自动配置是一个运行时（更准确地说，是应用程序启动时）的过程，考虑了众多因素，才决定Spring配置应该用哪个，不该用哪个。</p>
<p>举个例子，当我们使用Spring整合MyBatis的时候，需要完成如下几个步骤：</p>
<ul>
<li>根据数据库连接配置，配置一个dataSource对象；</li>
<li>根据dataSource对象和SqlMapConfig.xml文件（其中包含mapper.xml文件路径和mapper接口路径配置），配置一个sqlSessionFactory对象。</li>
</ul>
<p>当我们使用SpringBoot整合MyBatis的时候，会自动创建dataSource和sqlSessionFactory对象，只需我们在<code>application.yml</code>和Java配置中添加一些自定义配置即可。</p>
<p>在<code>application.yml</code>中配置好数据库连接信息及mapper.xml文件路径。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">spring:</span><br><span class="line">  datasource:</span><br><span class="line">    url: jdbc:mysql://localhost:3306/mall?useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=Asia/Shanghai</span><br><span class="line">    username: root</span><br><span class="line">    password: root</span><br><span class="line"></span><br><span class="line">mybatis:</span><br><span class="line">  mapper-locations:</span><br><span class="line">    - classpath:mapper/*.xml</span><br><span class="line">    - classpath*:com/**/mapper/*.xml</span><br></pre></td></tr></table></figure>

<p>使用Java配置，配置好mapper接口路径。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * MyBatis配置类</span><br><span class="line"> * Created by macro on 2019/4/8.</span><br><span class="line"> */</span><br><span class="line">@Configuration</span><br><span class="line">@MapperScan(&quot;com.macro.mall.tiny.mbg.mapper&quot;)</span><br><span class="line">public class MyBatisConfig &#123;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>使用自动配置以后，我们整合其他功能的配置大大减少了，可以更加专注程序功能的开发了。</p>
<h2 id="自定义配置"><a href="#自定义配置" class="headerlink" title="#自定义配置"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E9%85%8D%E7%BD%AE">#</a>自定义配置</h2><h3 id="自定义Bean覆盖自动配置"><a href="#自定义Bean覆盖自动配置" class="headerlink" title="#自定义Bean覆盖自动配置"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E8%87%AA%E5%AE%9A%E4%B9%89bean%E8%A6%86%E7%9B%96%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE">#</a>自定义Bean覆盖自动配置</h3><p>虽然自动配置很好用，但有时候自动配置的Bean并不能满足你的需要，我们可以自己定义相同的Bean来覆盖自动配置中的Bean。</p>
<p>例如当我们使用Spring Security来保护应用安全时，由于自动配置并不能满足我们的需求，我们需要自定义基于WebSecurityConfigurerAdapter的配置。这里我们自定义了很多配置，比如将基于Session的认证改为使用JWT令牌、配置了一些路径的无授权访问，自定义了登录接口路径，禁用了csrf功能等。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * SpringSecurity的配置</span><br><span class="line"> * Created by macro on 2018/4/26.</span><br><span class="line"> */</span><br><span class="line">@Configuration</span><br><span class="line">@EnableWebSecurity</span><br><span class="line">@EnableGlobalMethodSecurity(prePostEnabled = true)</span><br><span class="line">public class SecurityConfig extends WebSecurityConfigurerAdapter &#123;</span><br><span class="line">    @Autowired</span><br><span class="line">    private UmsAdminService adminService;</span><br><span class="line">    @Autowired</span><br><span class="line">    private RestfulAccessDeniedHandler restfulAccessDeniedHandler;</span><br><span class="line">    @Autowired</span><br><span class="line">    private RestAuthenticationEntryPoint restAuthenticationEntryPoint;</span><br><span class="line">    @Autowired</span><br><span class="line">    private IgnoreUrlsConfig ignoreUrlsConfig;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    protected void configure(HttpSecurity httpSecurity) throws Exception &#123;</span><br><span class="line">        List&lt;String&gt; urls = ignoreUrlsConfig.getUrls();</span><br><span class="line">        String[] urlArray = ArrayUtil.toArray(urls, String.class);</span><br><span class="line">        httpSecurity.csrf()// 由于使用的是JWT，我们这里不需要csrf</span><br><span class="line">                .disable()</span><br><span class="line">                .sessionManagement()// 基于token，所以不需要session</span><br><span class="line">                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)</span><br><span class="line">                .and()</span><br><span class="line">                .authorizeRequests()</span><br><span class="line">                .antMatchers(HttpMethod.GET,urlArray) // 允许对于网站静态资源的无授权访问</span><br><span class="line">                .permitAll()</span><br><span class="line">                .antMatchers(&quot;/admin/login&quot;)// 对登录注册要允许匿名访问</span><br><span class="line">                .permitAll()</span><br><span class="line">                .antMatchers(HttpMethod.OPTIONS)//跨域请求会先进行一次options请求</span><br><span class="line">                .permitAll()</span><br><span class="line">                .anyRequest()// 除上面外的所有请求全部需要鉴权认证</span><br><span class="line">                .authenticated();</span><br><span class="line">        // 禁用缓存</span><br><span class="line">        httpSecurity.headers().cacheControl();</span><br><span class="line">        // 添加JWT filter</span><br><span class="line">        httpSecurity.addFilterBefore(jwtAuthenticationTokenFilter(), UsernamePasswordAuthenticationFilter.class);</span><br><span class="line">        //添加自定义未授权和未登录结果返回</span><br><span class="line">        httpSecurity.exceptionHandling()</span><br><span class="line">                .accessDeniedHandler(restfulAccessDeniedHandler)</span><br><span class="line">                .authenticationEntryPoint(restAuthenticationEntryPoint);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    protected void configure(AuthenticationManagerBuilder auth) throws Exception &#123;</span><br><span class="line">        auth.userDetailsService(userDetailsService())</span><br><span class="line">                .passwordEncoder(passwordEncoder());</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Bean</span><br><span class="line">    public PasswordEncoder passwordEncoder() &#123;</span><br><span class="line">        return new BCryptPasswordEncoder();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Bean</span><br><span class="line">    public UserDetailsService userDetailsService() &#123;</span><br><span class="line">        //获取登录用户信息</span><br><span class="line">        return username -&gt; &#123;</span><br><span class="line">            AdminUserDetails admin = adminService.getAdminByUsername(username);</span><br><span class="line">            if (admin != null) &#123;</span><br><span class="line">                return admin;</span><br><span class="line">            &#125;</span><br><span class="line">            throw new UsernameNotFoundException(&quot;用户名或密码错误&quot;);</span><br><span class="line">        &#125;;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Bean</span><br><span class="line">    public JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter() &#123;</span><br><span class="line">        return new JwtAuthenticationTokenFilter();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Bean</span><br><span class="line">    @Override</span><br><span class="line">    public AuthenticationManager authenticationManagerBean() throws Exception &#123;</span><br><span class="line">        return super.authenticationManagerBean();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="自动配置微调"><a href="#自动配置微调" class="headerlink" title="#自动配置微调"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE%E5%BE%AE%E8%B0%83">#</a>自动配置微调</h3><p>有时候我们只需要微调下自动配置就能满足需求，并不需要覆盖自动配置的Bean，此时我们可以在<code>application.yml</code>属性文件中进行配置。</p>
<p>比如微调下应用运行的端口。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">server:</span><br><span class="line">  port: 8088</span><br></pre></td></tr></table></figure>

<p>比如修改下数据库连接信息。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">spring:</span><br><span class="line">  datasource:</span><br><span class="line">    url: jdbc:mysql://localhost:3306/mall?useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=Asia/Shanghai</span><br><span class="line">    username: root</span><br><span class="line">    password: root</span><br></pre></td></tr></table></figure>

<h3 id="读取配置文件的自定义属性"><a href="#读取配置文件的自定义属性" class="headerlink" title="#读取配置文件的自定义属性"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E8%AF%BB%E5%8F%96%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E7%9A%84%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B1%9E%E6%80%A7">#</a>读取配置文件的自定义属性</h3><p>有时候我们会在属性文件中自定义一些属性，然后在程序中使用。此时可以将这些自定义属性映射到一个属性类里来使用。</p>
<p>比如说我们想给Spring Security配置一个白名单，访问这些路径无需授权，我们可以先在<code>application.yml</code>中添添加如下配置。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">secure:</span><br><span class="line">  ignored:</span><br><span class="line">    urls:</span><br><span class="line">      - /</span><br><span class="line">      - /swagger-ui/</span><br><span class="line">      - /*.html</span><br><span class="line">      - /favicon.ico</span><br><span class="line">      - /**/*.html</span><br><span class="line">      - /**/*.css</span><br><span class="line">      - /**/*.js</span><br><span class="line">      - /swagger-resources/**</span><br><span class="line">      - /v2/api-docs/**</span><br></pre></td></tr></table></figure>

<p>之后创建一个属性类，使用<code>@ConfigurationProperties</code>注解配置好这些属性的前缀，再定义一个<code>urls</code>属性与属性文件相对应即可。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 用于配置白名单资源路径</span><br><span class="line"> * Created by macro on 2018/11/5.</span><br><span class="line"> */</span><br><span class="line">@Getter</span><br><span class="line">@Setter</span><br><span class="line">@Component</span><br><span class="line">@ConfigurationProperties(prefix = &quot;secure.ignored&quot;)</span><br><span class="line">public class IgnoreUrlsConfig &#123;</span><br><span class="line"></span><br><span class="line">    private List&lt;String&gt; urls = new ArrayList&lt;&gt;();</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Actuator"><a href="#Actuator" class="headerlink" title="#Actuator"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#actuator">#</a>Actuator</h2><p>SpringBoot Actuator的关键特性是在应用程序里提供众多Web端点，通过它们了解应用程序运行时的内部状况。</p>
<h3 id="端点概览"><a href="#端点概览" class="headerlink" title="#端点概览"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E7%AB%AF%E7%82%B9%E6%A6%82%E8%A7%88">#</a>端点概览</h3><p>Actuator提供了大概20个端点，常用端点路径及描述如下：</p>
<table>
<thead>
<tr>
<th>路径</th>
<th>请求方式</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>&#x2F;beans</td>
<td>GET</td>
<td>描述应用程序上下文里全部的Bean，以及它们之间关系</td>
</tr>
<tr>
<td>&#x2F;conditions</td>
<td>GET</td>
<td>描述自动配置报告，记录哪些自动配置生效了，哪些没生效</td>
</tr>
<tr>
<td>&#x2F;env</td>
<td>GET</td>
<td>获取全部环境属性</td>
</tr>
<tr>
<td>&#x2F;env&#x2F;{name}</td>
<td>GET</td>
<td>根据名称获取特定的环境属性</td>
</tr>
<tr>
<td>&#x2F;mappings</td>
<td>GET</td>
<td>描述全部的URI路径和控制器或过滤器的映射关系</td>
</tr>
<tr>
<td>&#x2F;configprops</td>
<td>GET</td>
<td>描述配置属性（包含默认值）如何注入Bean</td>
</tr>
<tr>
<td>&#x2F;metrics</td>
<td>GET</td>
<td>获取应用程序度量指标，比如JVM和进程信息</td>
</tr>
<tr>
<td>&#x2F;metrics&#x2F;{name}</td>
<td>GET</td>
<td>获取指定名称的应用程序度量值</td>
</tr>
<tr>
<td>loggers</td>
<td>GET</td>
<td>查看应用程序中的日志级别</td>
</tr>
<tr>
<td>&#x2F;threaddump</td>
<td>GET</td>
<td>获取线程活动的快照</td>
</tr>
<tr>
<td>&#x2F;health</td>
<td>GET</td>
<td>报告应用程序的健康指标，这些值由HealthIndicator的实现类提供</td>
</tr>
<tr>
<td>&#x2F;shutdown</td>
<td>POST</td>
<td>关闭应用程序</td>
</tr>
<tr>
<td>&#x2F;info</td>
<td>GET</td>
<td>获取应用程序的定制信息，这些信息由info打头的属性提供</td>
</tr>
</tbody></table>
<h3 id="查看配置明细"><a href="#查看配置明细" class="headerlink" title="#查看配置明细"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E6%9F%A5%E7%9C%8B%E9%85%8D%E7%BD%AE%E6%98%8E%E7%BB%86">#</a>查看配置明细</h3><ul>
<li>直接访问根端点，可以获取到所有端点访问路径，根端点访问地址：<a target="_blank" rel="noopener" href="http://localhost:8088/actuator">http://localhost:8088/actuator</a></li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    &quot;_links&quot;: &#123;</span><br><span class="line">        &quot;self&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator&quot;,</span><br><span class="line">            &quot;templated&quot;: false</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;beans&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/beans&quot;,</span><br><span class="line">            &quot;templated&quot;: false</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;caches-cache&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/caches/&#123;cache&#125;&quot;,</span><br><span class="line">            &quot;templated&quot;: true</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;caches&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/caches&quot;,</span><br><span class="line">            &quot;templated&quot;: false</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;health&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/health&quot;,</span><br><span class="line">            &quot;templated&quot;: false</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;health-path&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/health/&#123;*path&#125;&quot;,</span><br><span class="line">            &quot;templated&quot;: true</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;info&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/info&quot;,</span><br><span class="line">            &quot;templated&quot;: false</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;conditions&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/conditions&quot;,</span><br><span class="line">            &quot;templated&quot;: false</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;configprops&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/configprops&quot;,</span><br><span class="line">            &quot;templated&quot;: false</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;env&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/env&quot;,</span><br><span class="line">            &quot;templated&quot;: false</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;env-toMatch&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/env/&#123;toMatch&#125;&quot;,</span><br><span class="line">            &quot;templated&quot;: true</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;loggers&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/loggers&quot;,</span><br><span class="line">            &quot;templated&quot;: false</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;loggers-name&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/loggers/&#123;name&#125;&quot;,</span><br><span class="line">            &quot;templated&quot;: true</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;heapdump&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/heapdump&quot;,</span><br><span class="line">            &quot;templated&quot;: false</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;threaddump&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/threaddump&quot;,</span><br><span class="line">            &quot;templated&quot;: false</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;metrics-requiredMetricName&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/metrics/&#123;requiredMetricName&#125;&quot;,</span><br><span class="line">            &quot;templated&quot;: true</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;metrics&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/metrics&quot;,</span><br><span class="line">            &quot;templated&quot;: false</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;scheduledtasks&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/scheduledtasks&quot;,</span><br><span class="line">            &quot;templated&quot;: false</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;mappings&quot;: &#123;</span><br><span class="line">            &quot;href&quot;: &quot;http://localhost:8088/actuator/mappings&quot;,</span><br><span class="line">            &quot;templated&quot;: false</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>通过<code>/beans</code>端点，可以获取到Spring应用上下文中的Bean的信息，比如Bean的类型和依赖属性等，访问地址：<a target="_blank" rel="noopener" href="http://localhost:8088/actuator/beans">http://localhost:8088/actuator/beans</a></li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	&quot;contexts&quot;: &#123;</span><br><span class="line">		&quot;application&quot;: &#123;</span><br><span class="line">			&quot;beans&quot;: &#123;</span><br><span class="line">				&quot;sqlSessionFactory&quot;: &#123;</span><br><span class="line">					&quot;aliases&quot;: [],</span><br><span class="line">					&quot;scope&quot;: &quot;singleton&quot;,</span><br><span class="line">					&quot;type&quot;: &quot;org.apache.ibatis.session.defaults.DefaultSqlSessionFactory&quot;,</span><br><span class="line">					&quot;resource&quot;: &quot;class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]&quot;,</span><br><span class="line">					&quot;dependencies&quot;: [</span><br><span class="line">						&quot;dataSource&quot;</span><br><span class="line">					]</span><br><span class="line">				&#125;,</span><br><span class="line">				&quot;jdbcTemplate&quot;: &#123;</span><br><span class="line">					&quot;aliases&quot;: [],</span><br><span class="line">					&quot;scope&quot;: &quot;singleton&quot;,</span><br><span class="line">					&quot;type&quot;: &quot;org.springframework.jdbc.core.JdbcTemplate&quot;,</span><br><span class="line">					&quot;resource&quot;: &quot;class path resource [org/springframework/boot/autoconfigure/jdbc/JdbcTemplateConfiguration.class]&quot;,</span><br><span class="line">					&quot;dependencies&quot;: [</span><br><span class="line">						&quot;dataSource&quot;,</span><br><span class="line">						&quot;spring.jdbc-org.springframework.boot.autoconfigure.jdbc.JdbcProperties&quot;</span><br><span class="line">					]</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>通过<code>/conditions</code>端点，可以获取到当前应用的自动配置报告，<code>positiveMatches</code>表示生效的自动配置，<code>negativeMatches</code>表示没有生效的自动配置。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	&quot;contexts&quot;: &#123;</span><br><span class="line">		&quot;application&quot;: &#123;</span><br><span class="line">			&quot;positiveMatches&quot;: &#123;</span><br><span class="line">				&quot;DruidDataSourceAutoConfigure&quot;: [&#123;</span><br><span class="line">					&quot;condition&quot;: &quot;OnClassCondition&quot;,</span><br><span class="line">					&quot;message&quot;: &quot;@ConditionalOnClass found required class &#x27;com.alibaba.druid.pool.DruidDataSource&#x27;&quot;</span><br><span class="line">				&#125;]</span><br><span class="line">			&#125;,</span><br><span class="line">			&quot;negativeMatches&quot;: &#123;</span><br><span class="line">				&quot;RabbitAutoConfiguration&quot;: &#123;</span><br><span class="line">					&quot;notMatched&quot;: [&#123;</span><br><span class="line">						&quot;condition&quot;: &quot;OnClassCondition&quot;,</span><br><span class="line">						&quot;message&quot;: &quot;@ConditionalOnClass did not find required class &#x27;com.rabbitmq.client.Channel&#x27;&quot;</span><br><span class="line">					&#125;],</span><br><span class="line">					&quot;matched&quot;: []</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>通过<code>/env</code>端点，可以获取全部配置属性，包括环境变量、JVM属性、命令行参数和<code>application.yml</code>中的属性。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	&quot;activeProfiles&quot;: [],</span><br><span class="line">	&quot;propertySources&quot;: [&#123;</span><br><span class="line">			&quot;name&quot;: &quot;systemProperties&quot;,</span><br><span class="line">			&quot;properties&quot;: &#123;</span><br><span class="line">				&quot;java.runtime.name&quot;: &#123;</span><br><span class="line">					&quot;value&quot;: &quot;Java(TM) SE Runtime Environment&quot;</span><br><span class="line">				&#125;,</span><br><span class="line">				&quot;java.vm.name&quot;: &#123;</span><br><span class="line">					&quot;value&quot;: &quot;Java HotSpot(TM) 64-Bit Server VM&quot;</span><br><span class="line">				&#125;,</span><br><span class="line">				&quot;java.runtime.version&quot;: &#123;</span><br><span class="line">					&quot;value&quot;: &quot;1.8.0_91-b14&quot;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;,</span><br><span class="line">		&#123;</span><br><span class="line">			&quot;name&quot;: &quot;applicationConfig: [classpath:/application.yml]&quot;,</span><br><span class="line">			&quot;properties&quot;: &#123;</span><br><span class="line">				&quot;server.port&quot;: &#123;</span><br><span class="line">					&quot;value&quot;: 8088,</span><br><span class="line">					&quot;origin&quot;: &quot;class path resource [application.yml]:2:9&quot;</span><br><span class="line">				&#125;,</span><br><span class="line">				&quot;spring.datasource.url&quot;: &#123;</span><br><span class="line">					&quot;value&quot;: &quot;jdbc:mysql://localhost:3306/mall?useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=Asia/Shanghai&quot;,</span><br><span class="line">					&quot;origin&quot;: &quot;class path resource [application.yml]:6:10&quot;</span><br><span class="line">				&#125;,</span><br><span class="line">				&quot;spring.datasource.username&quot;: &#123;</span><br><span class="line">					&quot;value&quot;: &quot;root&quot;,</span><br><span class="line">					&quot;origin&quot;: &quot;class path resource [application.yml]:7:15&quot;</span><br><span class="line">				&#125;,</span><br><span class="line">				&quot;spring.datasource.password&quot;: &#123;</span><br><span class="line">					&quot;value&quot;: &quot;******&quot;,</span><br><span class="line">					&quot;origin&quot;: &quot;class path resource [application.yml]:8:15&quot;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>通过<code>/mappings</code>端点，可以查看全部的URI路径和控制器或过滤器的映射关系，这里可以看到我们自己定义的<code>PmsBrandController</code>和<code>JwtAuthenticationTokenFilter</code>的映射关系。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	&quot;contexts&quot;: &#123;</span><br><span class="line">		&quot;application&quot;: &#123;</span><br><span class="line">			&quot;mappings&quot;: &#123;</span><br><span class="line">				&quot;dispatcherServlets&quot;: &#123;</span><br><span class="line">					&quot;dispatcherServlet&quot;: [&#123;</span><br><span class="line">						&quot;handler&quot;: &quot;com.macro.mall.tiny.controller.PmsBrandController#createBrand(PmsBrand)&quot;,</span><br><span class="line">						&quot;predicate&quot;: &quot;&#123;POST /brand/create&#125;&quot;,</span><br><span class="line">						&quot;details&quot;: &#123;</span><br><span class="line">							&quot;handlerMethod&quot;: &#123;</span><br><span class="line">								&quot;className&quot;: &quot;com.macro.mall.tiny.controller.PmsBrandController&quot;,</span><br><span class="line">								&quot;name&quot;: &quot;createBrand&quot;,</span><br><span class="line">								&quot;descriptor&quot;: &quot;(Lcom/macro/mall/tiny/mbg/model/PmsBrand;)Lcom/macro/mall/tiny/common/api/CommonResult;&quot;</span><br><span class="line">							&#125;,</span><br><span class="line">							&quot;requestMappingConditions&quot;: &#123;</span><br><span class="line">								&quot;consumes&quot;: [],</span><br><span class="line">								&quot;headers&quot;: [],</span><br><span class="line">								&quot;methods&quot;: [</span><br><span class="line">									&quot;POST&quot;</span><br><span class="line">								],</span><br><span class="line">								&quot;params&quot;: [],</span><br><span class="line">								&quot;patterns&quot;: [</span><br><span class="line">									&quot;/brand/create&quot;</span><br><span class="line">								],</span><br><span class="line">								&quot;produces&quot;: []</span><br><span class="line">							&#125;</span><br><span class="line">						&#125;</span><br><span class="line">					&#125;]</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;,</span><br><span class="line">			&quot;servletFilters&quot;: [&#123;</span><br><span class="line">				&quot;servletNameMappings&quot;: [],</span><br><span class="line">				&quot;urlPatternMappings&quot;: [</span><br><span class="line">					&quot;/*&quot;,</span><br><span class="line">					&quot;/*&quot;,</span><br><span class="line">					&quot;/*&quot;,</span><br><span class="line">					&quot;/*&quot;,</span><br><span class="line">					&quot;/*&quot;</span><br><span class="line">				],</span><br><span class="line">				&quot;name&quot;: &quot;jwtAuthenticationTokenFilter&quot;,</span><br><span class="line">				&quot;className&quot;: &quot;com.macro.mall.tiny.component.JwtAuthenticationTokenFilter&quot;</span><br><span class="line">			&#125;]</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="查看运行时度量"><a href="#查看运行时度量" class="headerlink" title="#查看运行时度量"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E6%9F%A5%E7%9C%8B%E8%BF%90%E8%A1%8C%E6%97%B6%E5%BA%A6%E9%87%8F">#</a>查看运行时度量</h3><ul>
<li>通过<code>/metrics</code>端点，可以获取应用程序度量指标，不过只能获取度量的名称；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    &quot;names&quot;: [</span><br><span class="line">        &quot;http.server.requests&quot;,</span><br><span class="line">        &quot;jvm.buffer.count&quot;,</span><br><span class="line">        &quot;jvm.buffer.memory.used&quot;,</span><br><span class="line">        &quot;jvm.buffer.total.capacity&quot;,</span><br><span class="line">        &quot;jvm.classes.loaded&quot;,</span><br><span class="line">        &quot;jvm.classes.unloaded&quot;,</span><br><span class="line">        &quot;jvm.gc.live.data.size&quot;,</span><br><span class="line">        &quot;jvm.gc.max.data.size&quot;,</span><br><span class="line">        &quot;jvm.gc.memory.allocated&quot;,</span><br><span class="line">        &quot;jvm.gc.memory.promoted&quot;,</span><br><span class="line">        &quot;jvm.gc.pause&quot;,</span><br><span class="line">        &quot;jvm.memory.committed&quot;,</span><br><span class="line">        &quot;jvm.memory.max&quot;,</span><br><span class="line">        &quot;jvm.memory.used&quot;,</span><br><span class="line">        &quot;jvm.threads.daemon&quot;,</span><br><span class="line">        &quot;jvm.threads.live&quot;,</span><br><span class="line">        &quot;jvm.threads.peak&quot;,</span><br><span class="line">        &quot;jvm.threads.states&quot;,</span><br><span class="line">        &quot;logback.events&quot;,</span><br><span class="line">        &quot;process.cpu.usage&quot;,</span><br><span class="line">        &quot;process.start.time&quot;,</span><br><span class="line">        &quot;process.uptime&quot;,</span><br><span class="line">        &quot;system.cpu.count&quot;,</span><br><span class="line">        &quot;system.cpu.usage&quot;</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>需要添加指标名称才能获取对应的值，比如获取当前JVM使用的内存信息，访问地址：<a target="_blank" rel="noopener" href="http://localhost:8088/actuator/metrics/jvm.memory.used">http://localhost:8088/actuator/metrics/jvm.memory.used</a></li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    &quot;name&quot;: &quot;jvm.memory.used&quot;,</span><br><span class="line">    &quot;description&quot;: &quot;The amount of used memory&quot;,</span><br><span class="line">    &quot;baseUnit&quot;: &quot;bytes&quot;,</span><br><span class="line">    &quot;measurements&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;statistic&quot;: &quot;VALUE&quot;,</span><br><span class="line">            &quot;value&quot;: 3.45983088E8</span><br><span class="line">        &#125;</span><br><span class="line">    ],</span><br><span class="line">    &quot;availableTags&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;tag&quot;: &quot;area&quot;,</span><br><span class="line">            &quot;values&quot;: [</span><br><span class="line">                &quot;heap&quot;,</span><br><span class="line">                &quot;nonheap&quot;</span><br><span class="line">            ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;tag&quot;: &quot;id&quot;,</span><br><span class="line">            &quot;values&quot;: [</span><br><span class="line">                &quot;Compressed Class Space&quot;,</span><br><span class="line">                &quot;PS Survivor Space&quot;,</span><br><span class="line">                &quot;PS Old Gen&quot;,</span><br><span class="line">                &quot;Metaspace&quot;,</span><br><span class="line">                &quot;PS Eden Space&quot;,</span><br><span class="line">                &quot;Code Cache&quot;</span><br><span class="line">            ]</span><br><span class="line">        &#125;</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>通过<code>loggers</code>端点，可以查看应用程序中的日志级别信息，可以看出我们把<code>ROOT</code>范围日志设置为了INFO，而<code>com.macro.mall.tiny</code>包范围的设置为了DEBUG。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	&quot;levels&quot;: [</span><br><span class="line">		&quot;OFF&quot;,</span><br><span class="line">		&quot;ERROR&quot;,</span><br><span class="line">		&quot;WARN&quot;,</span><br><span class="line">		&quot;INFO&quot;,</span><br><span class="line">		&quot;DEBUG&quot;,</span><br><span class="line">		&quot;TRACE&quot;</span><br><span class="line">	],</span><br><span class="line">	&quot;loggers&quot;: &#123;</span><br><span class="line">		&quot;ROOT&quot;: &#123;</span><br><span class="line">			&quot;configuredLevel&quot;: &quot;INFO&quot;,</span><br><span class="line">			&quot;effectiveLevel&quot;: &quot;INFO&quot;</span><br><span class="line">		&#125;,</span><br><span class="line">		&quot;com.macro.mall.tiny&quot;: &#123;</span><br><span class="line">			&quot;configuredLevel&quot;: &quot;DEBUG&quot;,</span><br><span class="line">			&quot;effectiveLevel&quot;: &quot;DEBUG&quot;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>通过<code>/health</code>端点，可以查看应用的健康指标。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    &quot;status&quot;: &quot;UP&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="关闭应用"><a href="#关闭应用" class="headerlink" title="#关闭应用"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E5%85%B3%E9%97%AD%E5%BA%94%E7%94%A8">#</a>关闭应用</h3><p>通过POST请求<code>/shutdown</code>端点可以直接关闭应用，但是需要将<code>endpoints.shutdown.enabled</code>属性设置为true才可以使用。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    &quot;message&quot;: &quot;Shutting down, bye...&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="定制Actuator"><a href="#定制Actuator" class="headerlink" title="#定制Actuator"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E5%AE%9A%E5%88%B6actuator">#</a>定制Actuator</h3><p>有的时候，我们需要自定义一下Actuator的端点才能满足我们的需求。</p>
<ul>
<li>比如说Actuator有些端点默认是关闭的，我们想要开启所有端点，可以这样设置；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">management:</span><br><span class="line">  endpoints:</span><br><span class="line">    web:</span><br><span class="line">      exposure:</span><br><span class="line">        include: &#x27;*&#x27;</span><br></pre></td></tr></table></figure>

<ul>
<li>比如说我们想自定义Actuator端点的基础路径，比如改为<code>/monitor</code>，这样我们我们访问地址就变成了这个：<a target="_blank" rel="noopener" href="http://localhost:8088/monitor">http://localhost:8088/monitor</a></li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">management:</span><br><span class="line">  endpoints:</span><br><span class="line">    web:</span><br><span class="line">      base-path: /monitor</span><br></pre></td></tr></table></figure>

<h2 id="常用起步依赖"><a href="#常用起步依赖" class="headerlink" title="#常用起步依赖"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E5%B8%B8%E7%94%A8%E8%B5%B7%E6%AD%A5%E4%BE%9D%E8%B5%96">#</a>常用起步依赖</h2><p>起步依赖不仅能让构建应用的依赖配置更简单，还能根据提供给应用程序的功能将它们组织到一起，这里整理了一些常用的起步依赖。</p>
<h3 id="官方依赖"><a href="#官方依赖" class="headerlink" title="#官方依赖"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E5%AE%98%E6%96%B9%E4%BE%9D%E8%B5%96">#</a>官方依赖</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependencies&gt;</span><br><span class="line">    &lt;!--SpringBoot整合Web功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合Actuator功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合AOP功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-aop&lt;/artifactId&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合测试功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;</span><br><span class="line">        &lt;scope&gt;test&lt;/scope&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合注解处理功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-configuration-processor&lt;/artifactId&gt;</span><br><span class="line">        &lt;optional&gt;true&lt;/optional&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合Spring Security安全功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合Redis数据存储功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-data-redis&lt;/artifactId&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合Elasticsearch数据存储功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-data-elasticsearch&lt;/artifactId&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合MongoDB数据存储功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-data-mongodb&lt;/artifactId&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合AMQP消息队列功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-amqp&lt;/artifactId&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合Quartz定时任务功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-quartz&lt;/artifactId&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合JPA数据存储功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合邮件发送功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">&lt;/dependencies&gt;</span><br></pre></td></tr></table></figure>

<h3 id="第三方依赖"><a href="#第三方依赖" class="headerlink" title="#第三方依赖"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E7%AC%AC%E4%B8%89%E6%96%B9%E4%BE%9D%E8%B5%96">#</a>第三方依赖</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependencies&gt;</span><br><span class="line">    &lt;!--SpringBoot整合MyBatis数据存储功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.mybatis.spring.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;mybatis-spring-boot-starter&lt;/artifactId&gt;</span><br><span class="line">        &lt;version&gt;$&#123;mybatis-version.version&#125;&lt;/version&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合PageHelper分页功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;com.github.pagehelper&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;pagehelper-spring-boot-starter&lt;/artifactId&gt;</span><br><span class="line">        &lt;version&gt;$&#123;pagehelper-starter.version&#125;&lt;/version&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合Druid数据库连接池功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;com.alibaba&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;druid-spring-boot-starter&lt;/artifactId&gt;</span><br><span class="line">        &lt;version&gt;$&#123;druid.version&#125;&lt;/version&gt;</span><br><span class="line">    &lt;/dependency&gt;  </span><br><span class="line">    &lt;!--SpringBoot整合Springfox的Swagger API文档功能依赖--&gt;</span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;io.springfox&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;springfox-boot-starter&lt;/artifactId&gt;</span><br><span class="line">        &lt;version&gt;$&#123;springfox-version&#125;&lt;/version&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合MyBatis-Plus数据存储功能依赖--&gt;  </span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;com.baomidou&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;mybatis-plus-boot-starter&lt;/artifactId&gt;</span><br><span class="line">        &lt;version&gt;$&#123;mybatis-plus-version&#125;&lt;/version&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    &lt;!--SpringBoot整合Knife4j API文档功能依赖--&gt; </span><br><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;com.github.xiaoymin&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;knife4j-spring-boot-starter&lt;/artifactId&gt;</span><br><span class="line">        &lt;version&gt;$&#123;knife4j-version&#125;&lt;/version&gt;</span><br><span class="line">    &lt;/dependency&gt;        </span><br><span class="line">&lt;/dependencies&gt;</span><br></pre></td></tr></table></figure>

<h2 id="项目源码地址"><a href="#项目源码地址" class="headerlink" title="#项目源码地址"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_start.html#%E9%A1%B9%E7%9B%AE%E6%BA%90%E7%A0%81%E5%9C%B0%E5%9D%80">#</a>项目源码地址</h2><p><a target="_blank" rel="noopener" href="https://github.com/macrozheng/mall-learning/tree/master/mall-tiny-boot">https://github.com/macrozheng/mall-learning/tree/master/mall-tiny-boot</a></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io">十一星野</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io/2024/01/1e0f014a2244.html">https://ko25891wan.gitlab.io/2024/01/1e0f014a2244.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://ko25891wan.gitlab.io" target="_blank">小小程序员</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2024/01/4cf46916922f.html" title="给Swagger换了个新皮肤，瞬间高大上了！"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">给Swagger换了个新皮肤，瞬间高大上了！</div></div></a></div><div class="next-post pull-right"><a href="/2024/01/4ec2ca7d89bb.html" title="肝了一周总结的SpringBoot常用注解大全，看完就炉火纯青了！"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">肝了一周总结的SpringBoot常用注解大全，看完就炉火纯青了！</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">十一星野</div><div class="author-info__description">归途也还可爱</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io"><i class="fab fa-github"></i><span>关注我</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Gitlab"><i class="fab fa-gitlab" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:ko25891wan@outlook.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%89%8D%E8%A8%80"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AE%80%E4%BB%8B"><span class="toc-number">2.</span> <span class="toc-text">简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BC%80%E5%A7%8B%E4%BD%BF%E7%94%A8"><span class="toc-number">3.</span> <span class="toc-text">开始使用</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E5%BA%94%E7%94%A8"><span class="toc-number">3.1.</span> <span class="toc-text">创建应用</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E5%BA%94%E7%94%A8"><span class="toc-number">3.2.</span> <span class="toc-text">查看应用</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84"><span class="toc-number">3.2.1.</span> <span class="toc-text">项目结构</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%BA%94%E7%94%A8%E5%90%AF%E5%8A%A8%E7%B1%BB"><span class="toc-number">3.2.2.</span> <span class="toc-text">应用启动类</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95%E5%BA%94%E7%94%A8"><span class="toc-number">3.2.3.</span> <span class="toc-text">测试应用</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%BC%96%E5%86%99%E5%BA%94%E7%94%A8%E9%85%8D%E7%BD%AE"><span class="toc-number">3.2.4.</span> <span class="toc-text">编写应用配置</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%A1%B9%E7%9B%AE%E6%9E%84%E5%BB%BA%E8%BF%87%E7%A8%8B"><span class="toc-number">3.2.5.</span> <span class="toc-text">项目构建过程</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E8%B5%B7%E6%AD%A5%E4%BE%9D%E8%B5%96"><span class="toc-number">3.3.</span> <span class="toc-text">使用起步依赖</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E8%B5%B7%E6%AD%A5%E4%BE%9D%E8%B5%96%E7%9A%84%E5%A5%BD%E5%A4%84"><span class="toc-number">3.3.1.</span> <span class="toc-text">使用起步依赖的好处</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8C%87%E5%AE%9A%E5%9F%BA%E4%BA%8E%E5%8A%9F%E8%83%BD%E7%9A%84%E4%BE%9D%E8%B5%96"><span class="toc-number">3.3.2.</span> <span class="toc-text">指定基于功能的依赖</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%A6%86%E7%9B%96%E8%B5%B7%E6%AD%A5%E4%BE%9D%E8%B5%96%E4%B8%AD%E7%9A%84%E5%BA%93"><span class="toc-number">3.3.3.</span> <span class="toc-text">覆盖起步依赖中的库</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE"><span class="toc-number">3.4.</span> <span class="toc-text">使用自动配置</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E9%85%8D%E7%BD%AE"><span class="toc-number">4.</span> <span class="toc-text">自定义配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89Bean%E8%A6%86%E7%9B%96%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE"><span class="toc-number">4.1.</span> <span class="toc-text">自定义Bean覆盖自动配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE%E5%BE%AE%E8%B0%83"><span class="toc-number">4.2.</span> <span class="toc-text">自动配置微调</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AF%BB%E5%8F%96%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E7%9A%84%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B1%9E%E6%80%A7"><span class="toc-number">4.3.</span> <span class="toc-text">读取配置文件的自定义属性</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Actuator"><span class="toc-number">5.</span> <span class="toc-text">Actuator</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%AB%AF%E7%82%B9%E6%A6%82%E8%A7%88"><span class="toc-number">5.1.</span> <span class="toc-text">端点概览</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E9%85%8D%E7%BD%AE%E6%98%8E%E7%BB%86"><span class="toc-number">5.2.</span> <span class="toc-text">查看配置明细</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E8%BF%90%E8%A1%8C%E6%97%B6%E5%BA%A6%E9%87%8F"><span class="toc-number">5.3.</span> <span class="toc-text">查看运行时度量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B3%E9%97%AD%E5%BA%94%E7%94%A8"><span class="toc-number">5.4.</span> <span class="toc-text">关闭应用</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%9A%E5%88%B6Actuator"><span class="toc-number">5.5.</span> <span class="toc-text">定制Actuator</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E8%B5%B7%E6%AD%A5%E4%BE%9D%E8%B5%96"><span class="toc-number">6.</span> <span class="toc-text">常用起步依赖</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%98%E6%96%B9%E4%BE%9D%E8%B5%96"><span class="toc-number">6.1.</span> <span class="toc-text">官方依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%AC%AC%E4%B8%89%E6%96%B9%E4%BE%9D%E8%B5%96"><span class="toc-number">6.2.</span> <span class="toc-text">第三方依赖</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B9%E7%9B%AE%E6%BA%90%E7%A0%81%E5%9C%B0%E5%9D%80"><span class="toc-number">7.</span> <span class="toc-text">项目源码地址</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/c60470b9a892.html" title="Java集合使用注意事项总结">Java集合使用注意事项总结</a><time datetime="2024-02-03T04:58:22.000Z" title="发表于 2024-02-03 12:58:22">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/81fb7a201f29.html" title="无题">无题</a><time datetime="2024-02-03T03:15:31.812Z" title="发表于 2024-02-03 11:15:31">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/5737c1ec69a9.html" title="Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)">Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)</a><time datetime="2024-01-31T06:56:16.000Z" title="发表于 2024-01-31 14:56:16">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/f510db7d2f19.html" title="Spring常见面试题总结">Spring常见面试题总结</a><time datetime="2024-01-31T06:55:58.000Z" title="发表于 2024-01-31 14:55:58">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/9be065e9f288.html" title="redis 面试">redis 面试</a><time datetime="2024-01-31T06:55:55.000Z" title="发表于 2024-01-31 14:55:55">2024-01-31</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2023 - 2024 By 十一星野</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.staticfile.org/instant.page/5.2.0/instantpage.min.js" type="module"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div></body></html>